import { createSlice, PayloadAction } from '@reduxjs/toolkit'

const initialState = {
	avator: '',
	nickname: '',
	tel: ''
}

type State = typeof initialState

const userSlice = createSlice({
	name: 'user',
	initialState,
	reducers: {
		loginSuccess(state, action: PayloadAction<State>) {
			state.avator = action.payload.avator
			state.nickname = action.payload.nickname
			state.tel = action.payload.tel
		},
		setAvator(state, action: PayloadAction<string>) {
			state.avator = action.payload
		}
	}
})
export const { loginSuccess, setAvator } = userSlice.actions

export default userSlice